package org.example.controller;

import org.example.model.User;
import org.example.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
//@Scope设置bean的作用域，可为singleton、prototype
@Scope("prototype")
public class LoginController {
    //类注解1：属性注解
    //@Autowired
    //变量名必须和类名相对应
//    private LoginService loginService;

//    //类注解2：set注入

//    private LoginService loginService;
//    @Autowired
//    public void setLoginService(LoginService loginService) {
//        this.loginService = loginService;
//    }

    //类注解3：构造函数注入
    private LoginService loginService;
    //@Autowired该注解加不加该方法都行
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }
    /*@Autowired
    //如何变量名和下面相应的方法相对应，则就不需要@Qualifier("user1")
    @Qualifier("user1")
    private User u1;
    public void sayHi(){
        loginService.sayHi();
        System.out.println(u1.getName());
    }*/
    @Bean
    public User user1(){
        User user=new User();
        user.setName("user1");
        user.setPassword("password1");
        return user;
    }
    @Bean
    public User user2(){
        User user=new User();
        user.setName("user2");
        user.setPassword("password2");
        return user;
    }

}
